<template>
    <view class="page-invitation-list">
		<u-sticky>
			<!-- 只能有一个根元素 -->
			<view class="search-sticky">
				<u-row gutter="0">
					<u-col span="4" v-for="(item,index) in tab.list" :key="index">
						<view class="text-center">
                            <view class="inline-block" :class="tab.current == index ? 'current' : ''" @click="changeTab(index)">
                                <text class="name">{{ item.name }}</text>
                            </view>
                        </view> 
					</u-col>
				</u-row>
			</view>
		</u-sticky>
		<view class="p-4" v-if="tab.list[tab.current].records.length == 0">
            <u-empty text="暂无内容" mode="list"></u-empty>
        </view> 
		<view class="list">
			<view class="fly-cell" v-for="(item,index) in tab.list[tab.current].records" :key="index">
				<view class="content">
					<view>
					<fly-info label="邀请码" :value="item.id"></fly-info>
						<fly-info label="会员时间" :value="item.id"></fly-info>
						<fly-info label="过期时间" :value="item.id"></fly-info>
						<fly-info label="剩余次数" :value="item.id"></fly-info>
					</view>
				</view>
				<view class="value">
					<u-button v-if="tab.current == 0" class="btn-cyan" size="medium">发送</u-button>
				</view>
			</view>
		</view>
    </view>
</template>
<script setup lang="ts">
import FlyInfo from '@/components/FlyInfo';
import {onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
const {proxy} = getCurrentInstance() as ComponentInternalInstance;

let tab = reactive({
	current: 0,
	list:[
		{id:0, name: '可发送', records: [], current: 1, size: 10, total:0},
		{id:1, name: '已使用', records: [], current: 1, size: 10, total:0},
		{id:2, name: '已过期', records: [], current: 1, size: 10, total:0},
	]
});

const changeTab = (i) => {
	tab.current = i;
    if(tab.list[tab.current].records.length == 0){
        getList('refresh');
    }
}
const getList = (type) => {
    let obj = tab.list[tab.current];
      if(type == 'refresh'){  
        obj.current = 1;
        obj.list = [];
      }else{
        if(obj.total > obj.records.length){
          obj.current ++;        
        }else{
          uni.showToast({title:'没有更多了',icon: 'none'});
          return;
        }
      };
      let params = {
        current: obj.current,
        size: obj.size,
        // activityType: obj.id,
        // status: 0,
      };
      proxy.$http('get', '/admin/guildInvitation/xcxPage', proxy.$util.getParam(params) ,(data,msg) => {
        obj.records = obj.records.concat(data.records);
        obj.total = data.total;
      },msg => {

      })
};
onPullDownRefresh(() => {
	getList('refresh');
	setTimeout( () => {
		uni.stopPullDownRefresh();
	}, 1000);
});
onReachBottom(() =>{
	getList();
});
onShow(() => {
	getList('refresh');
})
</script>